/*
 * Copyright (C) 2014 Eduardo Pereira Montenegro <epereiramontenegro@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.bambole.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Eduardo Pereira Montenegro <epereiramontenegro@gmail.com>
 */
public class EntryFormatUtil {

    public static boolean isEmailAddressFormatValid(String emailAddress) {

        Pattern pattern = Pattern.compile("^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6}$");
        Matcher matcher = pattern.matcher(emailAddress);

        return matcher.matches();
    }

    public static boolean isWebAddressFormatValid(String webAddress) {

        Pattern pattern = Pattern.compile("^[a-z0-9.-]+\\.[a-z]{2,6}$");
        Matcher matcher = pattern.matcher(webAddress);

        return matcher.matches();
    }

    public static boolean isTelephoneNumberFormatValid(String telephoneNumber) {

        Pattern pattern = Pattern.compile("^[+(0-9]+[)\\-0-9]+[\\s]?[0-9]{1,}$");
        Matcher matcher = pattern.matcher(telephoneNumber);

        return matcher.matches();
    }

    public static boolean isCodeValid(String code) {

        Pattern pattern = Pattern.compile("^[A-Za-z0-9]+([\\/\\-\\.\\(\\)\\[\\]\\{\\}\\_\\+\\|\\#\\@\\%\\$]*[A-Za-z0-9]+)*$", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(code);

        return matcher.matches();

    }

    public static boolean isConfigurationNameValid(String name) {

        Pattern pattern = Pattern.compile("^[A-Z]+[A-Za-z0-9]*$");
        Matcher matcher = pattern.matcher(name);

        return matcher.matches();

    }

    public static boolean isTypeNameValid(String sequence) {

        Pattern pattern = Pattern.compile("^[^\\/\\-\\.\\(\\)\\[\\]\\{\\}\\_\\+\\|\\#\\@\\%\\$\\,\\*\\&\\!\\~\\:\\=\\¨\\\"\\'\\<\\>\\;]*$");
        Matcher matcher = pattern.matcher(sequence);

        return matcher.matches();

    }

    public static boolean isStatusSequenceValid(String sequence) {

        Pattern pattern = Pattern.compile("^[0-9]{2}$");
        Matcher matcher = pattern.matcher(sequence);

        return matcher.matches();

    }

}
